#pragma once

#include "Substitution.h"

#include "Classifier.h"

namespace uml {

Substitution::Substitution(const QString& umlType)
    : Realization(umlType) {}

void Substitution::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Realization::fromJson(json, errorList);
    contract_ = JsonSerializable::create<Classifier>(json.value("contract"), errorList);

    substitutingClassifier_ = JsonSerializable::create<Classifier>(json.value("substitutingClassifier"), errorList);

}

void Substitution::toJson(QJsonObject& json) {
    Realization::toJson(json);
    if (contract_) {
        QJsonObject contract_json;
        contract_->toJson(contract_json);
        json.insert("contract", contract_json);
    }
    if (substitutingClassifier_) {
        QJsonObject substitutingClassifier_json;
        substitutingClassifier_->toJson(substitutingClassifier_json);
        json.insert("substitutingClassifier", substitutingClassifier_json);
    }
}

/// <summary>
/// contract getter
/// The contract with which the substituting classifier complies.
/// </summary>
shared_ptr<Classifier> Substitution::contract() const {
    return contract_;
}

/// <summary>
/// contract setter
/// The contract with which the substituting classifier complies.
/// </summary>
void Substitution::setContract(shared_ptr<Classifier> value) {
    contract_ = value;
}

/// <summary>
/// substitutingClassifier getter
/// Instances of the substituting classifier are runtime substitutable where
/// instances of the contract classifier are expected.
/// </summary>
shared_ptr<Classifier> Substitution::substitutingClassifier() const {
    return substitutingClassifier_;
}

/// <summary>
/// substitutingClassifier setter
/// Instances of the substituting classifier are runtime substitutable where
/// instances of the contract classifier are expected.
/// </summary>
void Substitution::setSubstitutingClassifier(shared_ptr<Classifier> value) {
    substitutingClassifier_ = value;
}

} // namespace uml
